﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using SPIWareMVVM.ViewModels;
using DataAccess;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Data;

namespace SPIWareMVVM.Views.Commands
{
    public class ShowWorkOrdersListCommand : BaseCommand
    {
        ApplicationViewModel _sender { get; set; }
        ApplicationViewModel applicationViewModel { get; set; }

        public ShowWorkOrdersListCommand(BaseViewModel sender)
            : base(sender)
        {
            _sender = (ApplicationViewModel)sender;
        }

        public override void Execute(object parameter)
        {
            WorkOrderList list = null;
            if (parameter != null) list = (WorkOrderList)parameter;

            //if (list != null)
            //{
            if (mainWindow == null) mainWindow = (Window1)Window.GetWindow((WorkOrderList)list);

            if (mainWindow != null)
                applicationViewModel = (ApplicationViewModel)((ObjectDataProvider)mainWindow.Resources["applicationVM"]).ObjectInstance;
            if (applicationViewModel != null)
            {
                applicationViewModel.SelectedCustomer = null;
                mainWindow.HideLists();
                mainWindow.workOrdersList.DisplayClosedWorkOrders = false;

                //        list.lbWorkOrders.ItemsSource = null;
                //        list.lbWorkOrders.ItemsSource = ApplicationData.ocWorkOrders;
                //        list.lbWorkOrders.SelectedIndex = -1;

                //        list.cboParts.ItemsSource = null;
                //        list.cboParts.ItemsSource = ApplicationData.ocParts;

                //        list.cboCustomers.ItemsSource = ApplicationData.ocCustomers;

                //        list.lbWorkOrders.SelectedIndex = -1;

                ApplicationData.ClearAllExcept(new List<Type> { typeof(WorkOrder) });
                mainWindow.HideLists();

                mainWindow.workOrdersList.Visibility = Visibility.Visible;
                mainWindow.workOrdersList.dpWorkOrderEdit.Visibility = Visibility.Collapsed;
            }
            //}
            //else list.lbWorkOrders.ItemsSource = ApplicationData.ocWorkOrders;

            list.DisplayClosedWorkOrders = false;
        }
    }
}
